﻿using System.Web;
using System.Linq;
using ZWZ.Caching;
using EFCachingProvider.Caching;
using System.Collections.Generic;

namespace ZWZ.DBProvider
{
    public class DB : DataContext
    {
        const string ItemsKey = "DB.Ctx";

        public DB()
            : base()
        {
            base.Cache = new AspNetCache("DBEntities");
            base.CachingPolicy = CachingPolicy.NoCaching;
            base.Log = new DebugTextWriter();
        }

        public static DB Ctx
        {
            get
            {
                if (HttpContext.Current != null)
                {
                    if (!HttpContext.Current.Items.Contains(ItemsKey))
                        HttpContext.Current.Items.Add(ItemsKey, new DB());
                    return (DB)HttpContext.Current.Items[ItemsKey];
                }

                return null;
            }
        }
    }
}
